const path = require('path')
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')

module.exports = {

  //在服务器预先渲染页面，然后发送客户端
  mode: 'spa',
  //启用懒加载，按需加载
  lazyLoad: true,
  //缓存文件
  cache: true,
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    'nuxt-lodash',
  ],

  // transpileDependencies:['quill','vue-quill-editor'],
  plugins: [
    { src: '~/plugins/nuxt-swiper-plugin.js', ssr: true },
    { src: '~/plugins/icons', ssr: true },
    { src: '~/plugins/emoji-mart.js', ssr: true },
    { src: '~/plugins/vue-lazyload', ssr: true },
    { src: '~/plugins/footer.js', ssr: true },
    { src: '~/plugins/infinite-scroll.js', ssr: true },
    { src: "~/plugins/clipboard.js", ssr: true },
  ],
  css: [
    'quill/dist/quill.core.css',
    'quill/dist/quill.snow.css',
    'quill/dist/quill.bubble.css',
    'emoji-mart-vue/css/emoji-mart.css',
    '~/assets/css/main.css',
  ],
  build: {
    babel: {
      plugins: [
        [
          "component",
          {
            "libraryName": "element-ui",
            "styleLibraryName": "theme-chalk"
          }
        ]
      ]
    }
  },
  env: {
    WS_URL: process.env.WS_URL
  },
  axios: {
    // 启用反向代理
    proxy: true,
  },
  // 启用代理
  proxy: {

    '/prod-api': {
      target: 'http://106.52.100.34:8222', // 目标服务器地址
      // target: 'http://43.138.222.49:8001',
      changeOrigin: true, // 是否改变源地址
      pathRewrite: {
        '^/prod-api': '' // 重写路径
      }
    }
  },

  router: {
    middleware: 'my-middleware' // 应用到所有页面的中间件
  },

  /*
  ** Headers of the page
  */
  head: {
    title: '智创云社',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'author', name: 'author', content: '智创云社' },
      // 添加多个关键字
      { hid: 'keywords', name: 'keywords', content: '智创云社官网，智创云社，智创云社，智创云社开发，智创云社测试，智创云社运维，智创云社协会，智创云社部门，智创云社学习，智创云社编程，智创云社程序员，智创云社计算机，智创云社计算机学院，智创云社计算机系，智创云社程序员，大数据与计算机学院，智创云社软件工程，智创云社智创云社计算机技术与科学，智创云社大数据，智创云社物联网，智创云社比赛，智创云社创新创业，智创云社蓝桥杯，智创云社程序设计天梯赛，智创云社计算机设计大赛' },
      {
        hid: 'description', name: 'description', content: '智创云社官网，展示智创云社的活动内容，比赛信息，学习资料等。同时作在有问必答模块可以发布帖子进行技术与校园生活等方面的交流本网站,由智创云社提供技术支持与维护'
      }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: 'http://43.138.234.45:9000/clubs/云社.ico' }
    ]
  },
  experimental: {
    writeEarlyHints: false
  },
  /*
  ** Customize the progress bar color
  */
  loading: { color: '#3B8070' },
  /*
  ** Build configuration
  */
  build: {
    /*
    ** Run ESLint on save
    */
    terser: true,

    optimization: {
      splitChunks: {
        minSize: 10000,
        maxSize: 250000
      }
    },
    extend(config, ctx) {
      config.plugins.unshift(new LodashModuleReplacementPlugin)
      // rules[2].use[0] is babel-loader
      config.module.rules[2].use[0].options.plugins = ['lodash']
    },
    extractCSS: true,
    analyze: {
      analyzerMode: 'static'
    },
    transpile: [/^vuetify/],
    extend(config, ctx) {
      config.plugins.push(
        new VuetifyLoaderPlugin()
      )
    },

    //svg图标
    extend(config, { isDev, isClient }) {
      //   if (isDev && isClient) {
      //     config.module.rules.push({
      //       enforce: 'pre',
      //       test: /\.(js|vue)$/,
      //       loader: 'eslint-loader',
      //       exclude: /(node_modules)/
      //     })
      //   }
      const svgRule = config.module.rules.find(rule => rule.test.test('.svg'))
      svgRule.exclude = [path.resolve(__dirname, 'assets/svg')]
      // Includes /icons/svg for svg-sprite-loader
      config.module.rules.push({
        test: /\.svg$/,
        include: [path.resolve(__dirname, 'assets/svg')],
        loader: 'svg-sprite-loader',
        options: {
          symbolId: 'icon-[name]'
        }
      })
    },
  }

}

